<?php
$_GET['province_id'] = empty($_GET['province_id']) ? '' : intval($_GET['province_id']);
$orderby = get_major_key(array('userid' => 'DESC'));
$oAddress = new Address();
$oUser = new User();

if(!empty($_GET['btnExport'])){	// 导出
	$list = $oUser->get_list('*', $_GET, $orderby, $__page, $__pagesize, $offset = 0);
	if(!empty($list['list']) && is_array($list['list'])){
		$data = array();
		foreach($list['list'] as $row){
			switch($row['sex']){
				case 1:
					$row['sex'] = '男';
					break;
				case 2:
					$row['sex'] = '女';
					break;
				default:
					$row['sex'] = '保密';
			}
			//
			$row['province_name'] = $oAddress->get_province_by_id($row['province_id']);
			$row['city_name'] = $oAddress->get_city_by_id($row['city_id']);
			$row['area_name'] = $oAddress->get_area_by_id($row['area_id']);
			//
			$row['regtime'] = ftime($row['regtime']);
			$row['lsttime'] = ftime($row['lsttime']);
			$data[] = $row;
		}
		$headers = array(
			'userid'		=> array('title' => 'ID',			'width' => '6'),
			'username'		=> array('title' => '用户名', 		'width' => '12.5'),
			'realname'		=> array('title' => '真实姓名', 	'width' => '12.5'),
			'nickname'		=> array('title' => '昵称', 		'width' => '12.5'),
			'sex'			=> array('title' => '性别', 		'width' => '6'),
			'mobile'		=> array('title' => '手机', 		'width' => '12.5'),
			'email'			=> array('title' => '邮箱', 		'width' => '25'),
			'province_name'	=> array('title' => '省', 			'width' => '8'),
			'city_name'		=> array('title' => '市', 			'width' => '8'),
			'area_name'		=> array('title' => '区', 			'width' => '8'),
			'address'		=> array('title' => '地址', 		'width' => '50',	'wrap' => true),
			'regtime'		=> array('title' => '注册时间', 	'width' => '18'),
			'lsttime'		=> array('title' => '最后登录时间', 'width' => '18'),
		);
		if($list['total'] > 5000){	// 导出超过5000时用CSV
			export_csv($data, $headers, '_E_用户_'.date('Ymd_His').'.csv');
		}else{
			$oExcel = new Excel();
			$oExcel->export($headers, $data, '_E_用户_'.date('Ymd_His').'.xlsx');
		}
	}
	exit;
}

$list = $oUser->get_list('*', $_GET, $orderby, $__page, $__pagesize);
if(!empty($list['list']) && is_array($list['list'])){
	
	// 主键排序字段
	make_major_key_options(array(
		'userid'	=> '用户编号',
		'lsttime'	=> '最后登录',
	));

	foreach($list['list'] as $key => $row){
		switch($row['sex']){
			case 1:
				$row['sex'] = '男';
				break;
			case 2:
				$row['sex'] = '女';
				break;
			default:
				$row['sex'] = '保密';
		}
		//
		$row['province_name'] = $oAddress->get_province_by_id($row['province_id']);
		$row['city_name'] = $oAddress->get_city_by_id($row['city_id']);
		$row['area_name'] = $oAddress->get_area_by_id($row['area_id']);
		//
		$row['regtime'] = ftime($row['regtime']);
		$row['lsttime'] = ftime($row['lsttime']);
		$list['list'][$key] = $row;
	}
	$vars['list'] = $list['list'];
	$vars['pagelist'] = $list['pagelist'];
}

$provinces = $oAddress->get_provinces();
$vars['province_id_options'] = make_options($provinces, true, $_GET['province_id']);
?>